/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package core.threads.server.inGame;

import core.threads.server.Server_Public_Data;
import core.threads.server.Server_Public_MsgBox;

/**
 *
 * @author Invince
 */
public class T_Server_Deck_Processor  extends Thread{
/*----------Attributs-------------------*/
    protected boolean stop;
    protected boolean suspend;
/*----------Public functions------------*/
    @Override
    public void run() {
        /**-----Init-----**/
        /**-----Loop----**/
        while(!this.stop){
            if(!this.suspend){
                if(!Server_Public_MsgBox.msgBox_Deck_Process.isEmpty()){
                    Server_Public_MsgBox.Deck_Process temp=Server_Public_MsgBox.msgBox_Deck_Process.poll();
                    if(temp instanceof Server_Public_MsgBox.Deck_Process_Draw){
                        Server_Public_MsgBox.Deck_Process_Draw dPd=(Server_Public_MsgBox.Deck_Process_Draw) temp;
                        int sourceId=dPd.getSourceId();
//                        int sourceDeckId=dPd.getSourceDeckId();
//                        int targetId=dPd.getTargetId();
//                        int targetDeckId=dPd.getTargetDeckId();
                        int nbCard=dPd.getNbCard();
                        synchronized(Server_Public_Data.semaGame){
                            Server_Public_Data.game.drawCardFromBaseDeck(sourceId, nbCard);
                        }
                    }else if(temp instanceof Server_Public_MsgBox.Deck_Process_Move){
                        Server_Public_MsgBox.Deck_Process_Move dPm=(Server_Public_MsgBox.Deck_Process_Move) temp;
                        int sourceId=dPm.getSourceId();
                        int sourceDeckId=dPm.getSourceDeckId();
                        int cardId=dPm.getCardId();
                        synchronized(Server_Public_Data.semaGame){
                            Server_Public_Data.game.drawCard(sourceId, sourceDeckId, cardId);//卡片从target移到source
                        }
                    }
                    //刷新屏幕
                    Server_Public_MsgBox.refreshScreen();
                }
            }
        }
        /**----End-----**/
    }

    public void stopT(){
        synchronized(this){
            this.stop=true;
        }
    }

    public void suspendT(){
        synchronized(this){
            this.suspend=true;
        }
    }

    public void resumeT(){
        synchronized(this){
            this.suspend=false;
        }
    }
/*----------Private functions-----------*/
/*----------Constructor-----------------*/
    public T_Server_Deck_Processor() {
        synchronized(this){
            this.stop=false;
            this.suspend=false;
        }
    }
/*----------Gets and sets---------------*/

}
